(function( $ ) {
  $.fn.prettylikebox = function(options) {
  //color picker gradient (wuuuuttt)	
	
	function ColorLuminance(hex, lum) {
	// validate hex string
	hex = String(hex).replace(/[^0-9a-f]/gi, '');
	if (hex.length < 6) {
		hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
	}
	lum = lum || 0;
	// convert to decimal and change luminosity
	var rgb = "#", c, i;
	for (i = 0; i < 3; i++) {
		c = parseInt(hex.substr(i*2,2), 16);
		c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
		rgb += ("00"+c).substr(c.length);
	}
	return rgb;
}

var defaults = {  
    url : 'http%3A%2F%2Fwww.facebook.com%2Fplatform',  
    rounded: true,
	shadow: true,
	font:'light',
	height:258,
	width:500,
	stylesheet:'http://feelingabit.com/likemeh/plbstyle.css',
	appid:306076519473895,
	bg:0,
	startg:'#ffffff',
	endg:'#919191',
	border:'#2b2b2b'
}, 

settings = $.extend({}, defaults, options); 

		var sideborder= ColorLuminance(settings.border,4);

		var bordertop= ColorLuminance(settings.border,6);
		var borderbottom= ColorLuminance(settings.border,3);
		
		
		
//clean up the hex codes
$('<style type="text/css">@import url("http://feelingabit.com/likemeh/plbstyle.php?w='+settings.width+'&h='+settings.height+'&b='+settings.bg+'&s='+settings.startg.replace('#','')+'&e='+settings.endg.replace('#','')+'&sb='+sideborder.replace('#','')+'&bt='+bordertop.replace('#','')+'&bb='+borderbottom.replace('#','')'")</style>').appendTo("head");
  var currentObject = $(this) ;
  var divId= currentObject.attr("id");
  currentObject.addClass('plbwidget');
  if(settings.rounded) { currentObject.addClass('rounded');}  
  if(settings.shadow){currentObject.addClass('shadow');}  
  $('<div class="bg"></div>').appendTo(currentObject);
  $('#'+divId+' iframe').attr("src", '//www.facebook.com/plugins/likebox.php?href='+settings.url+'&width='+settings.width+'&border_color=none;height='+settings.height+'&colorscheme='+settings.font+'&show_faces=true&border_color&stream=false&header=false&appId='+settings.appid);
    $('#'+divId+' iframe').css("width", settings.width+8);
   };

})( jQuery );    